/*
 * 程序清单：这是一个 CAN 设备使用例程
 * 例程导出了 can_sample 命令到控制终端
 * 命令调用格式：can_sample can1
 * 命令解释：命令第二个参数是要使用的 CAN 设备名称，为空则使用默认的 CAN 设备
 * 程序功能：通过 CAN 设备发送一帧，并创建一个线程接收数据然后打印输出。
*/

#include <rtthread.h>
#include "rtdevice.h"
#include <board.h>

#ifndef ULOG_USING_SYSLOG
#define LOG_TAG              "led.test"
#define LOG_LVL              LOG_LVL_DBG
#include <ulog.h>
#else
#include <syslog.h>
#endif /* ULOG_USING_SYSLOG */


/* defined the LED0 pin: C10 */
#define LED1_PIN               GET_PIN(C, 10)
#define LED2_PIN               GET_PIN(C, 11)
#define LED3_PIN               GET_PIN(C, 12)
#define LED4_PIN               GET_PIN(D, 0)
#define LED5_PIN               GET_PIN(D, 1)
#define LED6_PIN               GET_PIN(D, 2)
#define LED7_PIN               GET_PIN(D, 3)
#define LED8_PIN               GET_PIN(D, 4)

int led_test(void)
{
    int count = 1;
    /* set LED0 pin mode to output */
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED5_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED6_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED7_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED8_PIN, PIN_MODE_OUTPUT);

    while (count++)
    {
        rt_pin_write(LED1_PIN, PIN_LOW);
        rt_pin_write(LED2_PIN, PIN_LOW);
        rt_pin_write(LED3_PIN, PIN_LOW);
        rt_pin_write(LED4_PIN, PIN_LOW);
        rt_pin_write(LED5_PIN, PIN_LOW);
        rt_pin_write(LED6_PIN, PIN_LOW);
        rt_pin_write(LED7_PIN, PIN_LOW);
        rt_pin_write(LED8_PIN, PIN_LOW);
        rt_thread_mdelay(500);
        rt_pin_write(LED1_PIN, PIN_HIGH);
        rt_pin_write(LED2_PIN, PIN_HIGH);
        rt_pin_write(LED3_PIN, PIN_HIGH);
        rt_pin_write(LED4_PIN, PIN_HIGH);
        rt_pin_write(LED5_PIN, PIN_HIGH);
        rt_pin_write(LED6_PIN, PIN_HIGH);
        rt_pin_write(LED7_PIN, PIN_HIGH);
        rt_pin_write(LED8_PIN, PIN_HIGH);
        rt_thread_mdelay(500);

    }

    return RT_EOK;
}

/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(led_test, led test sample);